package com.cloudwise.service.impl;

import com.cloudwise.dao.UserInfoDao;
import com.cloudwise.service.UserInfoService;
import com.cloudwise.util.MySqlSessionFactory;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2021/9/10 9:56
 * @description：用户业务实现类
 * @modified By：
 * @version: 1.0
 */
public class UserInfoServiceImpl  implements UserInfoService {
   // UserInfoDao userInfoDao= new UserInfoDaoImpl();
    SqlSession sqlSession=MySqlSessionFactory.getSqlSession();
   UserInfoDao userInfoDao= sqlSession.getMapper(UserInfoDao.class);;
    @Override
    public List<Map<String, Object>> findAllUserInfo(Map map) {
        int page=Integer.parseInt(map.get("page").toString());
        int limit=Integer.parseInt(map.get("limit").toString());
        List<Map<String, Object>> allUserInfo = userInfoDao.findAllUserInfo((page-1)*limit, limit);
        sqlSession.commit();
        return allUserInfo;
    }

    @Override
    public Map<String, Object> findUserByUserNameAndPassword(String username, String password) {
        return userInfoDao.findUserByUserNameAndPassword(username,password);
    }

    @Override
    public Map<String, Object> findUserByUserName(String username) {
        return userInfoDao.findUserByUserName(username);
    }

    @Override
    public Map<String, Object> findUserById(int id) {
        return userInfoDao.findUserById(id);
    }

    @Override
    public boolean addUser(Map map) {
        return userInfoDao.addUser(map);
    }

    @Override
    public boolean deleteUserById(int id ) {
        boolean b = userInfoDao.deleteUserById(id);
        sqlSession.commit();
        return b;

    }

    @Override
    public boolean deleteUser(Map map) {
        return false;
    }

    @Override
    public int findAllCount() {
        return userInfoDao.findAllCount();
    }
}
